@extends('backend::layout')
@section('title',trans($page_title))
@section('content')
    @if(isset($search_tpl))
        {{$search_tpl->render()}}
    @endif
    @component('backend::component.table.table-content')
        @slot('page_title') {{$page_title}} @endslot
        @slot('tools_btn')
            @component('backend::component.form.button')
                @slot('title') 添加广告 @endslot
                @slot('elem') a @endslot
                @slot('color') info @endslot
                @slot('icon') hcl-img-upload @endslot
                @slot('href')

                    {{$pos_id > 0 ?route('b_ShopAd_create',['pos_id'=>$pos_id]):route('b_ShopAd_adPos')}}

                @endslot
            @endcomponent
            @component('backend::component.form.button')
                @slot('title') 批量删除 @endslot
                @slot('btn') btn @endslot
                @slot('color') danger @endslot
                @slot('icon') hcl-remove @endslot
                @slot('class') btn-ajax @endslot
                @slot('params')
                    {"url":"{{route('b_ShopAd_delete')}}","method":"post","title":"删除广告","targetData":".id","confirm":"true"}
                @endslot
            @endcomponent
        @endslot
        @slot('body_content')
            @if($list->isNotEmpty())
                <table class="list table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>
                            @component('backend::component.checkbox')
                                @slot('name') ids-all @endslot
                            @endcomponent
                        </th>
                        <th>广告标题</th><th>图片</th><th>访问链接</th><th>点击量</th><th>状态</th><th>操作</th><th>位置</th>
                    </tr>
                    </thead>
                    <tbody>
                        @foreach($list->groupBy('pos_id') as $group)
                            @foreach($group as $value)
                            <tr>
                                <td>
                                    @component('backend::component.checkbox')
                                        @slot('name') id[] @endslot
                                        @slot('class') id @endslot
                                        @slot('value') {{$value->id}} @endslot
                                    @endcomponent
                                </td>
                                <td>{{$value->ad_name}}</td>
                                <td>
                                    {{--@if(check_file_exists($value->resource_link??0))--}}
                                        {{--<img style="height: 50px; max-width: 120px;" src="{{$value->resource_link}}">--}}
                                    {{--@else--}}
                                        {{--资源已丢失,请重新上传--}}
                                    {{--@endif--}}
                                    <img style="height: 50px; max-width: 120px;" src="{{$value->resource_link}}">
                                </td>
                                <td>{{$value->ad_link}}</td>
                                <td>{{$value->click_count}}</td>
                                <td>
                                    @component("backend::component.switch")
                                        @slot('params'){"url":"{{route('b_ShopAd_switchAd',['id'=>$value->id])}}"} @endslot
                                        @slot('checked') @if($value->status == 1) checked @endif @endslot
                                    @endcomponent
                                </td>
                                <td>
                                    @component('backend::component.form.button')
                                        @slot('title') 删除 @endslot
                                        @slot('icon') hcl-remove @endslot
                                        @slot('color') danger @endslot
                                        @slot('params') {"url":"{{route('b_ShopAd_delete',['id'=>$value->id])}}","confirm":"true"} @endslot
                                        @slot('class') btn-ajax @endslot
                                    @endcomponent
                                    @component('backend::component.form.button')
                                        @slot('title') 编辑 @endslot
                                        @slot('elem') a @endslot
                                        @slot('href') {{route('b_ShopAd_update',['ad_id'=>$value->id])}} @endslot
                                        @slot('icon') hcl-edit1 @endslot
                                        @slot('color') primary @endslot
                                    @endcomponent
                                </td>
                                @if($loop->index==0)
                                    <td rowspan="{{$loop->count}}">{{$value->pos->pos_name}}</td>
                                @endif
                            </tr>
                        @endforeach
                         @endforeach
                    </tbody>
                </table>
                @slot('list_page')
                    {{$list->appends($search_tpl->getSearchData())->links('backend::public.pagination')}}
                @endslot
            @else
                @component('backend::public.empty_page')
                    @slot('info') 暂时没有广告 @endslot
                @endcomponent
            @endif
        @endslot
    @endcomponent
@endsection